const Sequelize = require('sequelize')
const sequelize = require('../libs/db')
class User extends Sequelize.Model {}
User.init(
  {
    userId: {
      field: 'id',
      type: Sequelize.BIGINT,
      primaryKey: true,
      autoIncrement: true
    },
    openid: {
      field: 'openid',
      type: Sequelize.STRING(100),
      allowNull: true,
      unique: true,
      comment: '从小程序获取用户openid，允许为空'
    },
    deviceId: {
      field: 'device_id',
      type: Sequelize.STRING(100),
      allowNull: true,
      unique: true,
      comment: '从小程序获取用户设备ID，允许为空'
    },
    userName: {
      field: 'user_name',
      type: Sequelize.STRING(100),
      allowNull: false,
      comment: '用户名，昵称'
    },
    loginName: {
      field: 'login_name',
      type: Sequelize.STRING(100),
      allowNull: false,
      unique: true,
      comment: '用户登录名'
    },
    passwd: {
      field: 'passwd',
      type: Sequelize.STRING(100),
      allowNull: false,
      comment: '用户登录密码'
    },
    email: {
      field: 'email',
      type: Sequelize.STRING(100),
      allowNull: true,
      // unique: true,
      comment: '用户邮件'
    },
    mobile: {
      field: 'mobile',
      type: Sequelize.STRING(100),
      allowNull: true,
      unique: true,
      comment: '用户手机号，允许为空'
    },
    verifyCode: {
      field: 'verify_code',
      type: Sequelize.STRING(10),
      allowNull: true,
      comment: '手机验证码'
    },
    verifyTime: {
      field: 'verify_time',
      type: Sequelize.BIGINT,
      allowNull: true,
      comment: '手机验证码发送时间'
    },
    isActive: {
      field: 'is_active',
      type: Sequelize.SMALLINT,
      defaultValue: 0,
      comment: '用户是否激活：0 -> 未激活; 1 -> 已激活'
    },
    isAdmin: {
      field: 'is_admin',
      type: Sequelize.SMALLINT,
      defaultValue: 0,
      comment: '用户是否管理员：0 -> 否; 1 -> 是'
    },
    roleId: {
      field: 'role_id',
      type: Sequelize.BIGINT,
      defaultValue: 0,
      comment: '角色ID'
    },
    avatar: {
      field: 'avatar',
      type: Sequelize.STRING,
      comment: '用户自定义头像'
    },
    description: {
      field: 'description',
      type: Sequelize.TEXT,
      comment: '用户简介'
    },
    userInfo: {
      field: 'user_info',
      type: Sequelize.TEXT,
      comment: '从小程序授权获取的用户信息'
    },
    shareCode: {
      field: 'share_code',
      type: Sequelize.STRING(20),
      allowNull: false,
      defaultValue: 0,
      unique: true,
      comment: '用户的分享码'
    },
    refereeCode: {
      field: 'referee_code',
      type: Sequelize.STRING(20),
      allowNull: false,
      defaultValue: 0,
      comment: '介绍人的分享码'
    },
    userRegTime: {
      field: 'user_reg_time',
      type: Sequelize.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: '用户首次输入手机号注册时间'
    },
    userLoginTime: {
      field: 'user_login_time',
      type: Sequelize.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: '用户最后访问时间'
    },
    userToken: {
      field: 'user_token',
      type: Sequelize.STRING(50),
      allowNull: true,
      unique: true,
      comment: '用户token'
    },
    createdAt: {
      field: 'created_at',
      type: Sequelize.BIGINT
    },
    updatedAt: {
      field: 'updated_at',
      type: Sequelize.BIGINT
    }
  },
  {
    sequelize,
    modelName: 'user',
    tableName: 'user'
  }
)

module.exports = User
